package com.xhs.hawaii.invoice.controller;

import com.xhs.hawaii.common.PageResult;
import com.xhs.hawaii.common.utils.excel.ExcelUtil;
import com.xhs.hawaii.invoice.model.InvoiceApproveLog;
import com.xhs.hawaii.invoice.model.InvoiceOrderBag;
import com.xhs.hawaii.invoice.query.OrderForInvoicePageQuery;
import com.xhs.hawaii.invoice.vo.InvoiceVo;
import com.xhs.hawaii.invoice.vo.PurchaseOrderForInvoiceVo;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author wanggang
 * @since 1-24
 */
@RestController
@RequestMapping("/invoice")
public class InvoiceController {
    /**
     * 获取采购单展示列表
     * @author wanggang
     * @return
     */
    @RequestMapping(value = "/orderList" ,method = RequestMethod.GET)
    public PageResult<PurchaseOrderForInvoiceVo> getOrderList(OrderForInvoicePageQuery query){
        return null;
    }

    /**
     * 导入发票模板的接口
     * @return
     */
    @RequestMapping(value="/invoiceImportList",method= RequestMethod.GET)
    public List<InvoiceVo> invoiceExcelToList(@RequestParam(value = "file") MultipartFile file){
        if (null == file) {
            throw new RuntimeException("请上传文件");
        }
        String name = file.getOriginalFilename();
        if (!name.endsWith(".xlsx") && !name.endsWith(".xls")) {
            throw new RuntimeException("仅支持上传excel文件");
        }
        try {
            Workbook wb = ExcelUtil.transforWorkbook(file.getInputStream());
            //return statementInvoiceService.importInvoice( wb);
            return  null;

        } catch (IOException e) {
            throw new RuntimeException("仅支持上传excel文件");
        }
    }

    /**
     * 发票提交审核的接口。写入发票表以及发票订单关联表，初始话发票状态为待审核，
     * @author wanggang
     * @since 1-24
     */
    @RequestMapping(value = "/checkInvoice" ,method = RequestMethod.POST)
    public void submitInvoiceToCheck(InvoiceOrderBag invoiceOrderBag){

    }

    /**
     * 发票审批接口,写入审批记录表，修改发票表purchase_invoice状态
     * @author wanggang
     */
    @RequestMapping(value="/examInvoice" ,method =RequestMethod.POST)
    public void examInvoice(InvoiceApproveLog invoiceApproveLog){

    }
}
